<?php
function apires($data=[],$code=200,$msg="success")
{
    $data   = is_null($data) ? [] : $data;
    if(is_string($data)){

        $data   = ["data"=>$data];
    }

    if(is_array($data)){
        $data['code']   = $code;
        $data['msg']    = $msg;
    }

    if(is_object($data)){
        $data->code = $code;
        $data->msg  = $msg;
    }

    response($data)->send();
}

function changeTimeType($seconds){
    if ($seconds > 3600){
        $hours = intval($seconds/3600);
        $minutes = $seconds % 3600;
        $time = $hours.":".gmstrftime('%M:%S', $minutes);
    }else{
        $time = gmstrftime('%H:%M:%S', $seconds);
    }
    return $time;
}



/*
 * 打印日志
 */
if(!function_exists('mylogger')){

    function mylogger($content,$file = 'my.txt'){

        if(is_array($content)){
            $content = digui($content);
        }

        $logContent =  "\r\n".date('Y-m-d H:i:s')."\r\n";
        $logContent .= "------------------------ BEGIN -----------------------------"."\r\n";
        $logContent .= $content."\r\n";
        $logContent .= "-------------------------  END  ----------------------------"."\r\n";
        $logfile =  public_path()."/logs/".$file;
        $max_size = 50000000;
        if(file_exists($logfile) and (abs(filesize($logfile)) > $max_size)){
            unlink($logfile);
        }
        file_put_contents($logfile,$logContent , FILE_APPEND);
    }
}
